package org.admin.entity.domain;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@TableName("admin_files")
@Data
public class File {
    @Getter
    public enum TYPE {
        IMAGE(1),
        FILE(2);
        private final int value;
        TYPE(int value) {
            this.value = value;
        }
    }

    @TableId(type= IdType.AUTO)
    private String id;
    private String path;
    @TableField("user_id")
    private Integer userId;
    private String name;
    private Integer size;

    @TableField("folder_path")
    private String folderPath;

    @Setter(AccessLevel.NONE)
    private Integer type;

    @Setter(AccessLevel.NONE)
    @TableField(exist = false)
    private TYPE typeWith;

    private String format;

    @TableField("created_at")
    private Date createdAt;

    @TableField("updated_at")
    private Date updateAt;

    @TableLogic
    @TableField("deleted_at")
    private Date deletedAt;
    // 特征码
    private String signature;

    @TableField("content_type")
    private String contentType;
    public void setType(Integer type){
        if(type != null) {
            for (TYPE item : TYPE.values()) {
                if (item.getValue() == type) {
                    typeWith = item;
                    break;
                }
            }
        }else{
            typeWith = null;
        }
        this.type = type;
    }

    public void setTypeWith(TYPE typeWith){
        if(typeWith != null){
            type = typeWith.getValue();
        }else{
            type = null;
        }
        this.typeWith = typeWith;
    }

}
